<template>
  <view class="content">
    <view class="searchBox">
      <u-calendar :show="show" mode="range" @confirm="confirm" @close="show = false" :closeOnClickOverlay="true"
        :minDate="minDate" monthNum="13"></u-calendar>
      <view class="timeBox" @click="show = true">
        <span style="margin-right: 10rpx;">日期</span>
        <view class="time">
          <image src="../../static/img/time.png" mode=""></image>
          {{info.start_date}}
        </view>
        <view style="margin: 0 10rpx;">
          至
        </view>
        <view class="time">
          <image src="../../static/img/time.png" mode=""></image>
          {{info.end_date}}
        </view>
      </view>
      <view class="pickerBox">
        <view class="pickerItem" @tap="hourShow = true">
          <view class="frame">
            {{hourText}}
            <image class="lower" src="../../static/img/lower.png" mode=""></image>
          </view>
        </view>
        <view class="iptBox pickerItem">
          <input class="ipt" type="text" placeholder="输入关键词" placeholder-class="iptPla">
          <view class="searchBtn" @tap="getEducationalList()">
            搜索
          </view>
        </view>
      </view>
    </view>

    <view class="list">
      <view class="item" v-for="(i,k) in list" :key="k">
        <view class="topBox">
          <view class="brand" v-if="i.type == 1">
            入门测
          </view>
          <view class="brand" v-if="i.type == 2">
            模块测
          </view>
          <view class="brand" v-if="i.type == 3">
            阶段测
          </view>
          <view class="brand" v-if="i.type == 4">
            出门测
          </view>
          <view class="name">
            {{i.user.username}}
          </view>
          <view class="itemTime">
            【{{i.create_time}}】
          </view>

        </view>
        <view class="btmBox">
          <view class="label">
            内容:
          </view>
          <view class="itemContent">
            {{i.content}}
          </view>
          <view class="numBox" v-if="i.score >= 90">
            {{i.score}}
          </view>
          <view class="numBox" v-else style="color: #D43030;">
            {{i.score}}
          </view>
        </view>
      </view>
    </view>
    <!-- 测试类型下拉框 -->
    <u-picker :show="hourShow" :columns="hourColumns" keyName="label" @confirm="confirmHour"
      @cancel="hourShow = false"></u-picker>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        show: false,
        hourShow: false,
        hourText: "测试类型",
        minDate: '',
        maxDate: '',
        hourColumns: [
          [{
            label: '入门测',
            // 其他属性值
            id: 1
            // ...
          }, {
            label: '模块测',
            id: 2
          }, {
            label: '阶段测',
            id: 3
          }, {
            label: '出门测',
            id: 4
          }]
        ],
        info: {
          start_date: '',
          end_date: '',
          search_data: '',
          type: ''
        },
        list: []
      };
    },
    onLoad() {
      this.getDate()
      this.getEducationalList()
      this.chooseTimed()
    },
    methods: {
      // 设置默认日期，最大值为今天，最小值为去年今天
      chooseTimed() {
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        if (month <= 9) {
          month = '0' + month;
        }
        if (day <= 9) {
          day = '0' + day;
        }
        let minyear = year - 1;
        this.minDate = minyear + '-' + month + '-' + day;
        this.maxDate = year + '-' + month + '-' + day;
      },
      getDate() {
        const currentDate = new Date();
        const year = currentDate.getFullYear();
        const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 月份是从0开始的
        const day = currentDate.getDate().toString().padStart(2, '0');
        const formattedDate = `${year}/${month}/${day}`;
        this.info.start_date = formattedDate
        this.info.end_date = formattedDate
      },
      confirm(e) {
        this.info.start_date = e[0].replace(/-/g, "/");
        this.info.end_date = e[e.length - 1].replace(/-/g, "/");
        this.show = false
      },
      confirmHour(e) {
        this.hourText = e.value[0].label
        this.info.type = e.value[0].id
        this.hourShow = false
      },
      async getEducationalList() {
        const {
          data: res
        } = await uni.$http.post('school/others/getEducationalList', this.info)
        if (res.code != 1) {
          return this.toast.msg(res.msg)
        }
        res.data.forEach(i => {
          i.score = Math.floor(i.score)
        })
        this.list = res.data
      },

    }
  }
</script>

<style lang="scss">
  .content {
    .navigationBox {
      display: flex;
      align-items: center;
      height: 112rpx;
      padding: 0 77rpx 0 51rpx;

      .returnImg {
        width: 52rpx;
        height: 52rpx;
      }

      .title {
        flex: 1;
        text-align: center;
      }

      .addImg {
        width: 23rpx;
        height: 23rpx;
      }
    }

    .searchBox {
      width: 670rpx;
      margin: 0 auto;
      padding: 0 20rpx;

      .timeBox {
        display: flex;
        height: 78rpx;
        line-height: 78rpx;
        align-items: center;
        margin-bottom: 18rpx;
        font-size: 21rpx;

        .time {
          width: 250rpx;
          height: 78rpx;
          border-radius: 10rpx;
          background: #FFFFFF;
          border: 2rpx solid #FCF7F7;
          padding-left: 26rpx;
          color: #666;

          image {
            width: 35rpx;
            height: 35rpx;
            margin-right: 17rpx;
            vertical-align: middle;
          }
        }
      }

      .pickerBox {
        font-size: 28rpx;
        height: 66rpx;
        line-height: 66rpx;
        display: flex;

        .pickerItem {
          display: flex;

          .frame {
            position: relative;
            width: 192rpx;
            text-align: center;
            color: #666666;
            border: 2rpx solid #FCF7F7;

            .lower {
              width: 42rpx;
              height: 42rpx;
              position: absolute;
              top: 50%;
              transform: translateY(-50%);
              right: 10rpx;
            }
          }
        }
      }

      .iptBox {
        display: flex;

        .ipt {
          box-sizing: border-box;
          width: 345rpx;
          height: 66rpx;
          padding-left: 75rpx;
          border: 2rpx solid #FCF7F7;
          border-radius: 10rpx;
        }

        .iptPla {
          height: 66rpx;
          line-height: 66rpx;
          color: #999;
          font-size: 22rpx;
        }

        .searchBtn {
          display: inline-block;
          background: #A6A6A6;
          width: 100rpx;
          height: 66rpx;
          line-height: 66rpx;
          text-align: center;
          border-radius: 10rpx;
          margin-left: 20rpx;
          font-size: 24rpx;
        }
      }
    }

    .list {
      width: 674rpx;
      margin: 28rpx auto;

      .item {
        position: relative;
        width: 674rpx;
        min-height: 168rpx;
        border-radius: 18rpx;
        border: 2rpx solid #ECECEC;
        padding: 14rpx 25rpx;
        margin-bottom: 20rpx;

        .topBox {
          display: flex;
          align-items: center;
          font-size: 24rpx;

          .brand {
            width: 54rpx;
            height: 23rpx;
            line-height: 23rpx;
            text-align: center;
            border-radius: 5rpx;
            background: #2A82E4;
            font-size: 14rpx;
            color: #FFFFFF;
          }

          .name {
            color: #2A82E4;
            margin: 0 12rpx;
          }

          .itemTime {
            color: #A6A6A6;
          }

          .editBtn {
            width: 61rpx;
            height: 28rpx;
            line-height: 28rpx;
            text-align: center;
            color: #FFFFFF;
            font-size: 21rpx;
            border-radius: 5rpx;
            background: #00BAAD;
            margin-left: 12rpx;
          }
        }

        .btmBox {
          display: flex;
          font-size: 21rpx;
          margin-top: 10rpx;

          .label {
            width: 65rpx;
          }

          .itemContent {
            width: 453rpx;
            overflow: hidden;
            /* 确保超出容器的内容被裁剪 */
            text-overflow: ellipsis;
            /* 超出部分显示省略号 */
          }

          .numBox {
            position: absolute;
            top: 50%;
            right: 25rpx;
            transform: translateY(-50%);
            width: 96rpx;
            height: 96rpx;
            border-radius: 48rpx;
            text-align: center;
            line-height: 96rpx;
            background: #D0E2F7;
            border: 2rpx solid #ECECEC;
            font-size: 52rpx;
            color: #FF8D1A;
            margin-left: 20rpx;
          }
        }
      }
    }
  }
</style>